package day20210512;

import treenode.TreeNode;

/**
 * 剑指 Offer 55 - I. 二叉树的深度
 * 输入一棵二叉树的根节点，求该树的深度。从根节点到叶节点依次经过的节点（含根、叶节点）形成树的一条路径，最长路径的长度为树的深度。
 *      9
 *    / \
 *   3  20
 *     /
 *    12
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] a = {6,3,4,8,7,9,10};
        TreeNode root = TreeNode.CreateTree(a);
        System.out.println(solution.maxDepth(root));
    }
    public int maxDepth(TreeNode root) {
        if (root == null){
            return 0;
        }
        int left = maxDepth(root.left);
        int right = maxDepth(root.right);
        return Math.max(left, right) + 1;
    }
}
